package dongze.com.ckdj.service;

import android.os.Parcel;
import android.os.Parcelable;

import dongze.com.ckdj.data.entity.request.Record;
import dongze.com.ckdj.persistence.dao.ServerUploadTask;
import dongze.com.ckdj.persistence.dao.State;

/**
 * Created by fanqwz on 2017/8/1.
 */

public class ImageUploadTask implements Parcelable {
    int uploadProgress;
    State state = State.Undefined;
    String type;
    long id;
    long recordId;

    public ImageUploadTask(ImageUploadService.TaskWrapper taskWrapper) {
        uploadProgress = taskWrapper.percent;
        type = taskWrapper.getTask().getType();
        id = taskWrapper.getTask().getId();
        state = taskWrapper.state;
        recordId = taskWrapper.getTask().getRecordId();
    }

    public ImageUploadTask(ServerUploadTask task, int progress) {
        uploadProgress = progress;
        type = task.getType();
        id = task.getId();
        state = task.getState();
        recordId = task.getRecordId();
    }


    protected ImageUploadTask(Parcel in) {
        uploadProgress = in.readInt();
        state = State.values()[in.readInt()];
        type = in.readString();
        id = in.readLong();
        recordId = in.readLong();
    }

    public static final Creator<ImageUploadTask> CREATOR = new Creator<ImageUploadTask>() {
        @Override
        public ImageUploadTask createFromParcel(Parcel in) {
            return new ImageUploadTask(in);
        }

        @Override
        public ImageUploadTask[] newArray(int size) {
            return new ImageUploadTask[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(uploadProgress);
        dest.writeInt(state == null ? State.Undefined.ordinal() : state.ordinal());
        dest.writeString(type);
        dest.writeLong(id);
        dest.writeLong(recordId);
    }

    void readFromParcel(Parcel in) {
        uploadProgress = in.readInt();
        state = State.values()[in.readInt()];
        type = in.readString();
        id = in.readLong();
        recordId = in.readLong();
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public ImageUploadTask() {
    }

    public int getUploadProgress() {
        return uploadProgress;
    }

    public void setUploadProgress(int uploadProgress) {
        this.uploadProgress = uploadProgress;
    }

    public State getState() {
        return state;
    }

    public void setState(State state) {
        this.state = state;
    }

    public long getRecordId() {
        return recordId;
    }

    public void setRecordId(long recordId) {
        this.recordId = recordId;
    }
}
